package com.ruoyi.campus.service.impl;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.campus.mapper.MyOrderMapper;
import com.ruoyi.campus.domain.MyOrder;
import com.ruoyi.campus.service.IMyOrderService;

/**
 * 订单Service业务层处理
 *
 * @author zht
 * @date 2021-10-24
 */
@Service
public class MyOrderServiceImpl implements IMyOrderService {
    @Autowired
    private MyOrderMapper myOrderMapper;

    /**
     * 查询订单
     *
     * @param orderId 订单主键
     * @return 订单
     */
    @Override
    public MyOrder selectMyOrderByOrderId(String orderId) {
        return myOrderMapper.selectMyOrderByOrderId(orderId);
    }

    /**
     * 查询订单列表
     *
     * @param myOrder 订单
     * @return 订单
     */
    @Override
    public List<MyOrder> selectMyOrderList(MyOrder myOrder) {
        return myOrderMapper.selectMyOrderList(myOrder);
    }

    /**
     * 查询个人订单列表
     *
     * @param myOrder 订单
     * @param userId  用户Id
     * @return 订单集合
     */
    @Override
    public List<MyOrder> selectMyOrderListByUserId(MyOrder myOrder, Long userId) {
        return myOrderMapper.selectMyOrderListByUserId(myOrder, userId);
    }

    /**
     * 新增订单
     *
     * @param myOrder 订单
     * @return 结果
     */
    @Override
    public int insertMyOrder(MyOrder myOrder) {
        myOrder.setCreateTime(DateUtils.getNowDate());
        return myOrderMapper.insertMyOrder(myOrder);
    }

    /**
     * 修改订单
     *
     * @param myOrder 订单
     * @return 结果
     */
    @Override
    public int updateMyOrder(MyOrder myOrder) {
        return myOrderMapper.updateMyOrder(myOrder);
    }

    /**
     * 批量删除订单
     *
     * @param orderIds 需要删除的订单主键
     * @return 结果
     */
    @Override
    public int deleteMyOrderByOrderIds(String[] orderIds) {
        return myOrderMapper.deleteMyOrderByOrderIds(orderIds);
    }

    /**
     * 删除订单信息
     *
     * @param orderId 订单主键
     * @return 结果
     */
    @Override
    public int deleteMyOrderByOrderId(String orderId) {
        return myOrderMapper.deleteMyOrderByOrderId(orderId);
    }

    /**
     * 查询个人订单
     *
     * @param userId      用户ID
     * @param orderStatus 订单状态
     * @return 结果
     */
    @Override
    public List<Map<String, Object>> selectMyOrder(String userId, String orderStatus) {
        return myOrderMapper.selectMyOrder(userId, orderStatus);
    }

    /**
     * 评论订单
     *
     * @param orderId  订单ID
     * @param evaluate 评价内容
     * @return 结果
     */
    @Override
    public int evaluateOrderById(String orderId, String evaluate) {
        return myOrderMapper.evaluateOrderById(orderId, evaluate);
    }

    /**
     * 更新商品状态
     *
     * @param comId 商品Id
     * @return 结果
     */
    @Override
    public int updateCommStatus(String comId) {
        return myOrderMapper.updateCommStatus(comId);
    }

    /**
     * 取消订单
     *
     * @param orderId 订单Id
     * @param comId   商品Id
     * @return 结果
     */
    @Override
    public int cancelOrder(String orderId, String comId) {
        if (myOrderMapper.deleteMyOrderByOrderId(orderId) > 0) {
            return myOrderMapper.updateCommStatusNormal(comId);
        } else {
            return 0;
        }
    }

    /**
     * 确认订单
     * @param orderId 订单Id
     * @return 结果
     */
    @Override
    public int finishOrder(String orderId) {
        return myOrderMapper.finishOrder(orderId);
    }
}
